package com.chenwy.example.controller;

import com.chenwy.example.data.PageInfo;
import com.chenwy.example.entity.main.MiniProgramUser;
import com.chenwy.example.service.MiniProgramUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2019/5/6.
 */
@RestController
@RequestMapping(value="user")
@Slf4j
public class MiniProgramUserController {

    @Autowired
    private MiniProgramUserService miniProgramUserService;
    @RequestMapping(value="search",method = RequestMethod.GET)
    public Page<MiniProgramUser> search(MiniProgramUser user, PageInfo pageInfo){
        Page<MiniProgramUser> page = miniProgramUserService.search(user,pageInfo);
        return page;
    }


    @PutMapping(value = "save")
    public ResponseEntity<MiniProgramUser> save(MiniProgramUser user){
         miniProgramUserService.save(user);
         return ResponseEntity.ok(user);
    }

    @GetMapping(value="login")
    public ResponseEntity<?> login(){
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("token","11111111111111111111111111111");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return ResponseEntity.ok(map);
    }

    @GetMapping(value="updateUserInfo")
    public ResponseEntity<?> updateUserInfo(){
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("tokenExpired",false);
        return ResponseEntity.ok(map);
    }
}
